<?php

namespace app\backstage\validate;

use think\Validate;

class SpreadValidate extends Validate
{
    protected $rule = [
        'id' => 'require|number|gt:0',
        'novel_id' => 'require|number|gt:0',
        'type' => 'require|in:1,2',
        'key' => 'require',
        'value' => 'require|number|gt:0',
        'chapter_no' => 'require|number|gt:0',
        'name' => 'require|max:100',
        'enter_pop' => 'in:1',
        'force_switch' => 'require|in:0,1',
        'force_chapter_no' => 'number|egt:0',
        'quick_id' => 'require|number|gt:0',
        'chapter_words_fee' => 'number|gt:0',
        'field' => 'require|in:status,allow_register',
        'cost' => 'require|number|egt:0',
        'template_id' => 'require|number|egt:0'
    ];

    protected $message = [
        'quick_id' => '请选择App',
        'chapter_no' => '请选择章节',
        'chapter_words_fee' => '千字/书币，请输入正确的值'
    ];

    protected $scene = [
        'customNovelForm' => ['novel_id', 'type'],
        'setCustom' => ['key', 'value', 'novel_id'],
        'createLink' => ['novel_id', 'chapter_no', 'name', 'quick_id', 'enter_pop', 'force_switch', 'force_chapter_no', 'template_id', 'chapter_words_fee'],
        'editLink' => ['id', 'novel_id', 'quick_id', 'chapter_no', 'name', 'enter_pop', 'force_switch', 'force_chapter_no', 'chapter_words_fee'],
        'deleteLink' => ['id'],
        'linkInfoForm' => ['novel_id', 'chapter_no'],
        'changeCost' => ['id', 'cost'],
    ];

    public function sceneChangeLinkStatus()
    {
        return $this->only(['id', 'field', 'value'])
            ->remove('value', 'gt')
            ->append('value', 'in:0,1');
    }
}